/*
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-10-11 13:32:23
 * @LastEditors: 李天惊 uf_lee@163.com
 * @LastEditTime: 2025-02-25 17:30:16
 * @FilePath: \global-brain\global-brain-admin\src\api\login\index.ts
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved.
 */
import { useAxios } from '@/hooks/web/useAxios'
import type { UserType } from './types'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
const request = useAxios()

// export const loginApi = (data: UserLoginType) => {
//   return request.post({
//     url: '/user/login',
//     data
//   })
// }
export const loginApi = (data: any) => {
  return request.post({
    url: 'index.php/api/common',
    data: {
      code: 'ucLogin',
      data: data
    }
  })
}

// 退出登录
export const loginOutApi = () => {
  return request.post({
    url: 'index.php/api/common',
    headers: { token: wsCache.get('token') },
    data: {
      code: 'ucLoginOut',
      data: {}
    }
  })
}

export const getUserListApi = ({ params }: AxiosConfig) => {
  return request.get<{
    total: number
    list: UserType[]
  }>({ url: '/user/list', params })
}

export const getAdminRoleApi = ({ params }) => {
  return request.get<{
    list: AppCustomRouteRecordRaw[]
  }>({ url: '/role/list', params })
}

export const getTestRoleApi = ({ params }) => {
  return request.get<{
    list: string[]
  }>({ url: '/role/list', params })
}

// 注册
export const registerApi = (data: any) => {
  return request.post({
    url: 'index.php/api/common',
    data: {
      code: 'ucRegister',
      data: data
    }
  })
}
